package message;

import POJO.Courier;
import POJO.Express;
import POJO.MessageResponse;
import POJO.Parcel;
import POJO.Terminal;
import Utils.SendSMSHelper;
import Utils.TimeHelper;


public class MessageSend{

	
	private Parcel parcel;
	private Terminal terminal;
	private Courier courier;
	private Express express;
	private String msgTemplate;
	private String msg;
	private MessageResponse messageResponse;

	public MessageSend( Parcel parcel,Terminal terminal, Courier courier,Express express,String msgTemplate){
		this.parcel=parcel;
		this.terminal=terminal;
		this.courier=courier;
		this.msgTemplate=msgTemplate;
		this.express=express;
	}

	public MessageResponse send() {
			 msg = msgTemplate.replace("{expCompanyShortName}", courier.getCourier_company())
					 .replace("{devBranchShortAddr}", terminal.getBranch_Short_Addr())
					 .replace("{terminalName}", terminal.getTerminal_name())
					 .replace("{boxNum}",parcel.getBoxSeq())
					 .replace("{date}",(TimeHelper.formattingTime(parcel.getSaveTime())))
					 .replace("{getCode}", parcel.getCheckCode())
					 .replace("{hotLine}", terminal.getAdminPhone())
					 .replace("{courierPhone}", courier.getPhoneNum())
					 .replace("{expHotLine}", express.getHotLine())
					 .replace("{parcelNum}", parcel.getParcelNum());

			 		long smsId=SendSMSHelper.send(msg, parcel.getPhoneNum(),terminal.getSmsPlatform());
			 		messageResponse=new MessageResponse();
					messageResponse.setMessageId(smsId);
					messageResponse.setPackageId(parcel.getId());
					messageResponse.setContent(msg);
					if(terminal.getSmsPlatform()==4){
						messageResponse.setStatus(1);	
					}else{
						messageResponse.setStatus(0);
					}
					return messageResponse;
	}
}
